package cn.wolfcode.controller;

import cn.wolfcode.enums.ConsumptionReportEnums;
import cn.wolfcode.qo.ConsumptionReportQueryObject;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.IConsumptionReportService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/consumptionReport")
public class ConsumptionReportController {
    @Autowired
    IConsumptionReportService reportServiceService;
    @Autowired
    IBusinessService businessService;

    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") ConsumptionReportQueryObject qo){
        model.addAttribute("PageInfo",reportServiceService.query(qo));
        model.addAttribute("groupByItems", ConsumptionReportEnums.values());
        model.addAttribute("business",businessService.listAll());
        return "/businessReport/list";
    }


    @RequestMapping("/echart")
    public String echart(Model model,@ModelAttribute("qo") ConsumptionReportQueryObject qo){
        //查出所有的数据,pageSize为零,分页自动失效查询所有
        qo.setPageSize(0);
        PageInfo pageInfo = reportServiceService.query(qo);
        System.out.println(pageInfo.getList());
        model.addAttribute("items",pageInfo.getList());
        return "businessReport/echart";
    }
}
